﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar.Controls;
using DevComponents.DotNetBar;
using QLTuyenXe.BLL;
using QLTuyenXe.DAO;
using System.Collections;
using System.Data.SqlClient;
using QLTuyenXe.library;

namespace QLTuyenXe.GUI
{
    public partial class frmCongTy : DevComponents.DotNetBar.Office2007Form
    {
        BCONGTY ct = new BCONGTY();
        CONGTY congTy = new CONGTY();
        XuLyDL xly = new XuLyDL();
        ThongBao thongBao = new ThongBao();
        public frmCongTy()
        {
            InitializeComponent();
        }

        private void textBoxX2_TextChanged(object sender, EventArgs e)
        {

        }
        private void frmCongTy_Load(object sender, EventArgs e)
        {
            CheckQuyen();
            hienTT();
        }
        public void hienTT()
        {
            DataTable cty = ct.Select();
            txtMaCT.Text = cty.Rows[0][0].ToString();
            txtTenCT.Text = cty.Rows[0][1].ToString();
            txtDiaChi.Text = cty.Rows[0][2].ToString();
            txtSoDT.Text = cty.Rows[0][3].ToString();
            txtFax.Text = cty.Rows[0][4].ToString();
            txtGiamDoc.Text = cty.Rows[0][5].ToString();
        }

        private void labelX2_Click(object sender, EventArgs e)
        {

        }

        private void labelX3_Click(object sender, EventArgs e)
        {

        }

        private void labelX4_Click(object sender, EventArgs e)
        {

        }

        private void labelX1_Click(object sender, EventArgs e)
        {

        }

        private void panelEx1_Click(object sender, EventArgs e)
        {

        }

        private void groupPanel1_Click(object sender, EventArgs e)
        {

        }

        private void textBoxX5_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBoxX4_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBoxX3_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBoxX1_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            if (MessageBoxEx.Show("Bạn thật sự muốn thoát không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
            {
                this.Close();
            }
        }

        private void textBoxX4_TextChanged_1(object sender, EventArgs e)
        {

        }

        private void txtSoDT_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
                MessageBoxEx.Show("Xin lỗi bạn số điện thoại là dạng số");
            }
        }

        private void btnCapNhat_Click_1(object sender, EventArgs e)
        {
            if (xly.nhom(txtTenCT.Text) == true && xly.HoTen(txtGiamDoc.Text) == true)
            {
                int kq = 0;
                CONGTY congTy = new CONGTY();
                congTy.TenCT = xly.ChuanHoa(txtTenCT.Text);
                congTy.Hoten = xly.ChuanHoa(txtGiamDoc.Text);
                congTy.DiaChi = xly.ChuanHoa(txtDiaChi.Text);
                congTy.SoDT = txtSoDT.Text;
                congTy.Fax = txtFax.Text;
                kq = ct.Update(congTy, "maCT=N'" + txtMaCT.Text + "'");
                if (kq > 0)
                {
                    hienTT();
                    thongBao.Sua();
                }
                else
                {
                    thongBao.LoiSua();
                }
            }
            else
            {
                thongBao.KiemTraSo();
            }
        }
        //check quyen (Mr.Tuyen)
        public static string ten = string.Empty;
        public void CheckQuyen()
        {
            BUser user = new BUser();
            DataTable sua = user.Select_Quyen("name='" + ten + "'", "ht_sua='X'");
            if (sua.Rows.Count > 0)
            {
                btnCapNhat.Enabled = true;
            }
            else
            {
                btnCapNhat.Enabled = false;
            }
        }
    }
}
